/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgLevelCamera
    {
        private readonly Dictionary<int, CfgLevelCamera> _dataMap;
        private readonly List<CfgLevelCamera> _dataList;


        public TbCfgLevelCamera(ByteBuf _buf)
        {
            //first read common data
            _TbCommonLevelCamera _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonLevelCamera(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgLevelCamera>(size * 3 / 2);
            _dataList = new List<CfgLevelCamera>(size);

            for (int i = 0; i < size; i++)
            {
                CfgLevelCamera _v;
                _v = CfgLevelCamera.DeserializeCfgLevelCamera(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgLevelCamera> DataMap => _dataMap;
        public IReadOnlyList<CfgLevelCamera> DataList => _dataList;

        public CfgLevelCamera Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgLevelCamera] config not found,id:" + key.ToString());

            return null;
        }

        public CfgLevelCamera GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "levelcamera";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgLevelCamera LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgLevelCamera(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgLevelCamera
    {
        private CfgLevelCamera(ByteBuf _buf, _TbCommonLevelCamera _commonData)
        {
            Id = _buf.ReadInt();
            Remark = _buf.ReadString();
            XAngle = _buf.ReadInt();
            YAngle = _buf.ReadInt();
            YAngleMin = _buf.ReadInt();
            YAngleMax = _buf.ReadInt();
            Distance = _buf.ReadInt();

            PostInit();
        }

        internal static CfgLevelCamera DeserializeCfgLevelCamera(ByteBuf _buf, _TbCommonLevelCamera _commonData)
        {
            return new CfgLevelCamera(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 策划备注 ---- 编辑器专用
        /// </summary>
        private string Remark { get; set; }
        /// <summary>
        /// 镜头X轴角度(上下，限制20-70)
        /// </summary>
        public int XAngle { get; private set; }
        /// <summary>
        /// 镜头Y轴角度(左右)
        /// </summary>
        public int YAngle { get; private set; }
        /// <summary>
        /// Y轴旋转角度左限制
        /// </summary>
        public int YAngleMin { get; private set; }
        /// <summary>
        /// Y轴旋转角度右限制
        /// </summary>
        public int YAngleMax { get; private set; }
        /// <summary>
        /// 镜头到玩家距离(厘米)
        /// </summary>
        public int Distance { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonLevelCamera
    {

        internal _TbCommonLevelCamera(ByteBuf _buf)
        {
        }

    }
}
